import Vue from "vue";

Vue.directive("resize", {
  bind(el, binding, vnode) {
    let width = "",
      height = "",
      i = 0;
    const get = async () => {
      const style = document.defaultView.getComputedStyle(el);
      if (width !== style.width || height !== style.height) {
        i++;
        if (i > 1) {
          vnode.context.myChart.resize();
        }
      }
      width = style.width;
      height = style.height;
    };
    const resize = async () => {};
    Vue.prototype.$worker
      .run(() => 100)
      .then(res => {
        resize();
        el.__vueReize__ = setInterval(get, res);
      });
  },
  unbind(el) {
    clearInterval(el.__vueReize__);
  }
});
